package com.mzy.javaapi.String;

import org.testng.annotations.Test;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/6/23 9:46
 * @Version 1.0
 */
public class StringArrToString {
    /**
     * 如果是 “字符串数组” 转 “字符串”，只能通过循环，没有其它方法
     * String[] str = {"abc", "bcd", "def"};
     * StringBuffer sb = new StringBuffer();
     * for(int i = 0; i < str.length; i++){
     * sb. append(str[i]);
     * }
     * String s = sb.toString();
     * <p>
     * 如果是 “字符数组” 转 “字符串” 可以通过下边的方法
     * char[]   data={'a','b','c'};
     * String  s=new   String(data);
     */

    private static final String[] str = {"abc", "bcd", "def"};

    /**
     * java8 可以用join
     */
    @Test
    public void test01() {

        String join = String.join(",", str);
        System.out.println(join);
        char[] data = {'a', 'b', 'c'};
        String s = new String(data);
        System.out.println(s);
    }

    @Test
    public void test02() {
        String[] str = {"abc", "bcd", "def"};
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < str.length; i++) {
            sb.append(str[i]);
        }
        System.out.println(sb.toString());
    }

    /**
     * char
     */
    @Test
    public void test03() {
        char[] data = {'a', 'b', 'c'};
        String s = new String(data);
        System.out.println(s);

    }

}
